<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nginx 多站点配置完全指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e293b;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #334155;
            padding: 8px 16px;
            font-size: 14px;
            color: #94a3b8;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
            color: #e2e8f0;
            font-size: 14px;
            line-height: 1.6;
        }
        .step-number {
            width: 40px;
            height: 40px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            flex-shrink: 0;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .floating-icon {
            animation: float 3s ease-in-out infinite;
        }
        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
        }
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #e5e7eb, transparent);
            margin: 3rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center">
            <div class="floating-icon inline-block mb-6">
                <i class="fas fa-server text-6xl opacity-90"></i>
            </div>
            <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">Nginx 多站点配置</h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                掌握虚拟主机配置艺术，在一台服务器上优雅地托管多个网站
            </p>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="py-16 px-6">
        <div class="max-w-4xl mx-auto">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12 card-hover">
                <div class="flex items-start space-x-4 mb-6">
                    <i class="fas fa-lightbulb text-3xl text-purple-600"></i>
                    <div>
                        <h2 class="text-2xl font-bold mb-4">核心概念</h2>
                        <p class="text-gray-700 leading-relaxed text-lg">
                            配置 Nginx 多站点（虚拟主机）涉及创建和启用不同的配置文件，每个配置文件定义了一个虚拟主机的设置。通过使用 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">server</code> 块来指定虚拟主机的域名、根目录、索引文件以及其他配置，可以在同一台服务器上托管多个网站。
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Architecture Visualization -->
    <section class="py-12 px-6">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-3xl font-bold text-center mb-12 gradient-text">架构概览</h2>
            <div class="bg-white rounded-2xl shadow-lg p-8">
                <div class="mermaid">
                    graph TB
                        A[客户端请求] --> B{Nginx}
                        B --> C[demo1.com]
                        B --> D[demo2.com]
                        B --> E[默认站点]
                        C --> F[/var/www/demo1]
                        D --> G[/var/www/demo2]
                        E --> H[/var/www/default]
                        
                        style A fill:#f9f,stroke:#333,stroke-width:2px
                        style B fill:#bbf,stroke:#333,stroke-width:2px
                        style C fill:#bfb,stroke:#333,stroke-width:2px
                        style D fill:#bfb,stroke:#333,stroke-width:2px
                        style E fill:#fbf,stroke:#333,stroke-width:2px
                </div>
            </div>
        </div>
    </section>

    <div class="section-divider"></div>

    <!-- Virtual Host Concept -->
    <section class="py-12 px-6">
        <div class="max-w-4xl mx-auto">
            <div class="flex items-center mb-8">
                <i class="fas fa-globe text-4xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold">虚拟主机的基本概念</h2>
            </div>
            <div class="bg-gradient-to-r from-purple-50 to-pink-50 rounded-2xl p-8">
                <p class="text-lg text-gray-700 leading-relaxed">
                    虚拟主机（Virtual Host）允许在同一台服务器上使用不同的域名（或 IP 地址）托管多个网站。Nginx 通过 <code class="bg-white px-3 py-1 rounded shadow-sm">server</code> 块来实现虚拟主机功能，每个 server 块定义一个独立的网站配置。
                </p>
            </div>
        </div>
    </section>

    <!-- Configuration Steps -->
    <section class="py-16 px-6">
        <div class="max-w-5xl mx-auto">
            <h2 class="text-4xl font-bold text-center mb-16 gradient-text">配置步骤</h2>
            
            <!-- Step 1 -->
            <div class="mb-16">
                <div class="flex items-start space-x-6 mb-8">
                    <div class="step-number">1</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4">创建配置文件</h3>
                        <p class="text-gray-700 mb-6 leading-relaxed">
                            每个虚拟主机都有一个单独的配置文件。配置文件通常位于 <code class="bg-gray-100 px-2 py-1 rounded">/etc/nginx/sites-available/</code> 目录。
                        </p>
                        
                        <div class="space-y-6">
                            <div class="code-block">
                                <div class="code-header">
                                    <span><i class="fas fa-file-code mr-2"></i>demo1.com 配置</span>
                                    <span class="text-xs">/etc/nginx/sites-available/demo1</span>
                                </div>
                                <pre><code>server {
    listen 80;
    server_name demo1.com www.demo1.com;

    root /var/www/demo1;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}</code></pre>
                            </div>
                            
                            <div class="code-block">
                                <div class="code-header">
                                    <span><i class="fas fa-file-code mr-2"></i>demo2.com 配置</span>
                                    <span class="text-xs">/etc/nginx/sites-available/demo2</span>
                                </div>
                                <pre><code>server {
    listen 80;
    server_name demo2.com www.demo2.com;

    root /var/www/demo2;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Step 2 -->
            <div class="mb-16">
                <div class="flex items-start space-x-6 mb-8">
                    <div class="step-number">2</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4">启用虚拟主机</h3>
                        <p class="text-gray-700 mb-6 leading-relaxed">
                            使用符号链接将配置文件从 sites-available 目录链接到 sites-enabled 目录：
                        </p>
                        
                        <div class="code-block">
                            <div class="code-header">
                                <span><i class="fas fa-terminal mr-2"></i>创建符号链接</span>
                            </div>
                            <pre><code>sudo ln -s /etc/nginx/sites-available/demo1 /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/demo2 /etc/nginx/sites-enabled/</code></pre>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Step 3 -->
            <div class="mb-16">
                <div class="flex items-start space-x-6 mb-8">
                    <div class="step-number">3</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4">创建网站根目录</h3>
                        <p class="text-gray-700 mb-6 leading-relaxed">
                            为每个站点创建相应的根目录，并放置 index.html 文件：
                        </p>
                        
                        <div class="space-y-4">
                            <div class="code-block">
                                <div class="code-header">
                                    <span><i class="fas fa-folder-plus mr-2"></i>创建目录</span>
                                </div>
                                <pre><code>sudo mkdir -p /var/www/demo1
sudo mkdir -p /var/www/demo2</code></pre>
                            </div>
                            
                            <div class="code-block">
                                <div class="code-header">
                                    <span><i class="fas fa-file-alt mr-2"></i>创建首页文件</span>
                                </div>
                                <pre><code>echo "&lt;h1&gt;Welcome to demo1&lt;/h1&gt;" | sudo tee /var/www/demo1/index.html
echo "&lt;h1&gt;Welcome to demo2&lt;/h1&gt;" | sudo tee /var/www/demo2/index.html</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Step 4 -->
            <div class="mb-16">
                <div class="flex items-start space-x-6 mb-8">
                    <div class="step-number">4</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4">测试并重载配置</h3>
                        <p class="text-gray-700 mb-6 leading-relaxed">
                            在应用配置之前，先测试配置文件的正确性：
                        </p>
                        
                        <div class="space-y-4">
                            <div class="code-block">
                                <div class="code-header">
                                    <span><i class="fas fa-check-circle mr-2"></i>测试配置</span>
                                </div>
                                <pre><code>sudo nginx -t</code></pre>
                            </div>
                            
                            <div class="code-block">
                                <div class="code-header">
                                    <span><i class="fas fa-sync-alt mr-2"></i>重载 Nginx</span>
                                </div>
                                <pre><code>sudo systemctl reload nginx</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <div class="section-divider"></div>

    <!-- Advanced Configuration -->
    <section class="py-16 px-6">
        <div class="max-w-5xl mx-auto">
            <h2 class="text-4xl font-bold text-center mb-16 gradient-text">高级配置选项</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- SSL/TLS Configuration -->
                <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                    <div class="flex items-center mb-6">
                        <i class="fas fa-lock text-3xl text-green-600 mr-4"></i>
                        